//
//  CYDiscoverSearchView.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/3.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CYDiscoverSearchView: UIView {

    
    @IBOutlet weak var textFiledTraling: NSLayoutConstraint!
    @IBOutlet weak var searchView: UITextField!
    
    @IBOutlet weak var clickButton: UIButton!
    
//    class func searchView () -> CYDiscoverSearchView {
//        
//        return NSBundle.mainBundle().loadNibNamed("CYDiscoverSearchView", owner: nil, options: nil).last! as! CYDiscoverSearchView
// 
//    }
    
    class func seaView () ->CYDiscoverSearchView {
        
        return NSBundle.mainBundle().loadNibNamed("CYDiscoverSearchView", owner: nil, options: nil).last! as! CYDiscoverSearchView
    
        
    }
    private lazy var leftView:UIImageView = {
        let view = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        
        view.contentMode = .Center
        
        return view
    }()
    
    override func awakeFromNib() {
        leftView.frame.size = CGSize(width: self.frame.height, height: self.frame.height)
        searchView.leftView = leftView
        
        searchView.leftViewMode = .Always
        
    }
    
    
    @IBAction func editingChange(sender: AnyObject) {
        print("开始编辑")
        
        self.textFiledTraling.constant = self.clickButton.frame.width
        
        UIView.animateWithDuration((0.25)) { () -> Void in
            self.searchView.layoutIfNeeded()
            
        }
    }
    
    @IBAction func exitedChange(sender: AnyObject) {
        print("end")
        textFiledTraling.constant = 0
        
        searchView.resignFirstResponder()
        
        UIView.animateWithDuration((0.25)) { () -> Void in
            
            self.searchView.layoutIfNeeded()
        }
        
    }
    
}
